﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the GNU General Public License version 2 (GPLv2).
// See accompanying file License.txt or copy at http://phuse.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Phuse.Mime
{
    using System;
    using System.IO;

    /// <summary>The common base class of all header fields (see <a href="http://www.ietf.org/rfc/rfc5322.txt">RFC
    /// 5322</a> 2.2.).</summary>
    /// <threadsafety static="true" instance="false"/>
    public abstract class HeaderField : IVisitable<HeaderField>
    {
        private readonly string name;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>Gets the name of the header field.</summary>
        public string Name
        {
            get { return this.name; }
        }

        /// <summary>See <see cref="IVisitable{T}.Accept"/>.</summary>
        public abstract void Accept(IVisitor<HeaderField> visitor);

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal HeaderField(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Cannot be null or empty.", "name");
            }

            this.name = name;
        }

        internal abstract void WriteTo(Stream stream);
    }
}